package com.iscale.service.impl;

import com.github.pagehelper.PageHelper;
import com.iscale.model.dto.PageInfo;
import com.iscale.model.entity.SysLog;
import com.iscale.service.SystemLogService;
import com.iscale.mapper.SysLogMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by andychen83 on 2017/2/28.
 */
@Service
@Transactional
public class SystemLogServiceImpl  implements SystemLogService {
    private static final Logger log = LoggerFactory.getLogger(SystemLogServiceImpl.class);

    @Autowired
    private ThreadPoolTaskExecutor taskExecutor;

    @Autowired
    private SysLogMapper sysLogMapper;

    @Override
    public void insertSysControllerLog(SysLog runningLog) {
        taskExecutor.execute(() -> sysLogMapper.insert(runningLog));
    }

    @Override
    public PageInfo selectLog(int page, int rows, String sort, String order, String method, String url, String param, String result) {
        int counts = sysLogMapper.selectCounts();
        PageHelper.startPage(page, rows);
        List<SysLog> list = sysLogMapper.selectLog(sort, order, method, url, param, result);
        log.debug(list.toString());
        return new PageInfo(counts, list);
    }
}
